#include <stdio.h>
#include <fcntl.h>

int main()
{	
	pid_t pid = fork();
	int fd = open("f_fork.txt",O_CREAT | O_RDWR , 0666);
	if(fd == -1) perror("open") , exit(-1);
//	pid_t pid = fork();
	
	if(pid == 0)	//子进程 
	{
		printf("fd = %d\n",fd);
		write(fd,"abc",sizeof("abc"));
		sleep(1);
		close(fd);
		exit(0);
	}
	write(fd,"123",sizeof("123"));	
	printf("fd = %d\n",fd);	sleep(1);
	close(fd);
	return 0; 
}
